<?php
	/*
	 * AJAX call to save an edited or new TEXT message in the "publicity" table of the database.
	 *
	 * Variables:
	 *   id (int) 				: Record ID of the SMS message, 0 if new SMS
	 *   txt (string) 			: The body of the SMS message
	 *   datetime (datetime) 	: First time the message will be shown
	 *
	 * Returns: string: error or SMS message
	 *
	 */

	if($_POST["id"] > 0){
		$sql = mysql_query("UPDATE publicity SET pubText=\"".mysql_real_escape_string(stripslashes($_POST["txt"]))."\", pubFirstdate=\"".mysql_real_escape_string(stripslashes($_POST["datetime"]))."\", pubUpdateDate=NOW() WHERE pubID=".round($_POST["id"])." LIMIT 1");
	}else{
		$sql = mysql_query("INSERT INTO publicity SET pubText=\"".mysql_real_escape_string(stripslashes($_POST["txt"]))."\", pubFirstdate=\"".mysql_real_escape_string(stripslashes($_POST["datetime"]))."\", pubUpdateDate=NOW()");
	}
	if(mysql_error() != ""){
		echo "Error updating...";
		echo '<br />';
		echo mysql_error();
	}else{
		if($_POST["id"] > 0){
			echo mysql_real_escape_string(stripslashes($_POST["txt"]));
		}else{
			echo mysql_insert_id();
		}
	}
	exit;
?>